import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';


import {AppComponent} from './app.component';
import {LoginComponent} from './component/login/login.component';
import {RegisterComponent} from './component/register/register.component';
import {HomeComponent} from './component/home/home.component';
import {ProductDetailsComponent} from './component/product-details/product-details.component';
import {ShoppingCartComponent} from './component/shopping-cart/shopping-cart.component';
import {RouterModule, Routes} from '@angular/router';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {HttpClientModule} from '@angular/common/http';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import {MatButtonModule, MatInputModule, MatMenuModule, MatTabsModule} from '@angular/material';
import {FormsModule, NgForm} from '@angular/forms';
import {ProductComponent} from './component/product/product.component';
import {HttpService} from './share/service/http.service';
import {UserService} from './share/service/user.service';
import {CookieService} from 'angular2-cookie/services/cookies.service';
import {NavigationComponent} from './component/navigation/navigation.component';
import { RouteguardService } from './share/service/routeguard-service.service';
const routeConfig: Routes = [
  {
    path: '',   // 初始路由重定向[写在第一个]
    redirectTo: 'login',
    pathMatch: 'full'  // 必须要设置
  },
  {path: '', component: LoginComponent},
  {path: 'login', component: LoginComponent},
  {path: 'register', component: RegisterComponent},
  {path: 'home', component: HomeComponent, canActivate: [RouteguardService]},
  {path: 'product-details/:productId', component: ProductDetailsComponent, canActivate: [RouteguardService]},
  {path: 'shopping-cart', component: ShoppingCartComponent,  canActivate: [RouteguardService]},
  {
    path: '**',   // 错误路由重定向[写在最后一个]
    redirectTo: 'home',
    pathMatch: 'full'  // 必须要设置
  }
];

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    RegisterComponent,
    HomeComponent,
    ProductDetailsComponent,
    ShoppingCartComponent,
    ProductComponent,
    NavigationComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    RouterModule.forRoot(routeConfig),
    NgbModule.forRoot(),
    BrowserAnimationsModule,
    FormsModule,
    MatButtonModule, MatInputModule, MatTabsModule, MatMenuModule

  ],
  providers: [HttpService, UserService, CookieService,RouteguardService],
  bootstrap: [AppComponent]
})
export class AppModule {}
